package cn.kuporo.seckill.goods.controller;

import cn.kuporo.seckill.common.model.dto.SeckillGoodsDTO;
import cn.kuporo.seckill.common.model.response.Response;
import cn.kuporo.seckill.common.model.vo.FindGoodsByAVReqVO;
import cn.kuporo.seckill.common.model.vo.FindGoodsByIVReqVO;
import cn.kuporo.seckill.goods.application.service.SeckillGoodsService;
import cn.kuporo.seckill.goods.domain.model.SeckillGoods;
import cn.kuporo.seckill.goods.domain.model.vo.GoodsSaveReqVO;
import cn.kuporo.seckill.goods.domain.model.vo.GoodsUpdateStatusReqVO;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: kuporo
 * @since: 2025/7/7
 * @description:
 */
@RestController
@RequestMapping(value = "/goods")
@RequiredArgsConstructor
public class SeckillGoodsController {
    private final SeckillGoodsService seckillGoodsService;

    /**
     * 保存秒杀商品
     */
    @PostMapping("/save")
    public Response<?> saveSeckillGoods(@RequestBody @Validated GoodsSaveReqVO goodsSaveReqVO){
        return seckillGoodsService.saveSeckillGoods(goodsSaveReqVO);
    }

    /**
     * 更新商品状态
     */
    @PostMapping("/updateStatus")
    public Response<?> updateStatus(@RequestBody @Validated GoodsUpdateStatusReqVO goodsUpdateStatusReqVO){
        return seckillGoodsService.updateStatus(goodsUpdateStatusReqVO);
    }









    /**
     * 获取商品详情
     */
    @PostMapping( "/getById")
    public Response<SeckillGoods> getSeckillGoodsId(Long id){
        return Response.success(seckillGoodsService.getSeckillGoodsById(id));
    }

    /**
     * 获取商品列表
     */
    @PostMapping( "/getSeckillGoodsByActivityId")
    public Response<List<SeckillGoods>> getSeckillGoodsByActivityId(Long activityId){
        return Response.success(seckillGoodsService.getSeckillGoodsByActivityId(activityId));
    }


    @PostMapping( "/listByAV")
    public Response<List<SeckillGoodsDTO>> getSeckillGoodsByActivityId(@RequestBody @Validated FindGoodsByAVReqVO findGoodsByAVReqVO){
        return Response.success( seckillGoodsService.getSeckillGoodsList(findGoodsByAVReqVO.getActivityId(), findGoodsByAVReqVO.getVersion()));
    }

    /**
     * 获取商品详情（带缓存）
     */
    @PostMapping("/getByIV")
    public Response<SeckillGoodsDTO> getSeckillGoods(@RequestBody @Validated FindGoodsByIVReqVO findGoodsByIVReqVO){
        return Response.success(seckillGoodsService.getSeckillGoods(findGoodsByIVReqVO.getGoodsId(), findGoodsByIVReqVO.getVersion()));
    }
}
